import { imageView } from "sscrp/rppub/components/image";

//打开影像和展示联查凭证按钮处理逻辑
function imagAndVoucherHandle() {
    let imagAndVoucherOpsPromise = null;
    let billInfoMap = {};
    billInfoMap.pk_billid = this.currentRowData.busiid.value;
    billInfoMap.pk_billtype = this.currentRowData.billtypecode.value;
    billInfoMap.pk_tradetype = this.currentRowData.transtypecode.value;
    billInfoMap.pk_org = this.currentRowData.pk_org.value;

    //存在外系统，创建外系统请求Promise备用
    if (this.alreadySettingOts) {
        imagAndVoucherOpsPromise = this.requestApi.imagAndVoucherOps({
            isImagInstalled: this.isImagInstalled,
            billid: billInfoMap.pk_billid,
            tradeType: billInfoMap.pk_tradetype,
            pk_org: billInfoMap.pk_org,
            pk_group: this.currentRowData.pk_group.value
        })
    }

    // TOP 打开未处理单据时打开影像 ADD
    if (this.isImagInstalled && this.state.activeTabKey == 'todo') {
        if (this.alreadySettingOts) { //外系统打开方式
            imagAndVoucherOpsPromise.then((data) => {
                data = data.data;
                if (data.imagShowType == 1) {
                    openPage(data.imagShowUrl, data.imagShowName);
                } else if (data.imagShowType == 2) {
                    imageView(billInfoMap, 'iweb');
                }
            })
        } else {
            imageView(billInfoMap, 'iweb');
        }

    }
    // BTM 打开单据直接打开影像

    //是否显示联查凭证按钮
    let showLinkVoucherBtn = false;
    if (this.alreadySettingOts) {
        imagAndVoucherOpsPromise.then((data) => {
            data = data.data;
            if (data.voucherShowType == 1) {
                //显示联查凭证按钮
                showLinkVoucherBtn = true;
            }
            this.setState({
                showLinkVoucherBtn
            })
        })
    } else {
        this.setState({
            showLinkVoucherBtn
        })
    }

}

function openPage(url, name) {
    let w = (window.screen || {}).width || 1440;
    let h = (window.screen || {}).height || 900;
    let l = (window.screen || {}).width || 1440;
    let t = (window.screen || {}).height || 900;
    if (window.opener == null) {
        window.imageBrowserWin = window.open(url, name, "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
    } else {
        window.imageBrowserWin = window.opener.open(url, name, "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + ",toolbar=no, menubar=no, scrollbars=no, resizable=yes, location=no, status=no");
    }
}

export { imagAndVoucherHandle }